package com.papper.common.domain;

import com.google.common.collect.Maps;

import java.util.Map;

public class JdbcTypeHelp {
    private static       JdbcTypeHelp        instance = null;
    private static final Map<String, String> JavaType = Maps.newHashMap();
    private static final Map<String, String> JdbcType = Maps.newHashMap();

    public static synchronized JdbcTypeHelp I() {
        if (instance == null) {
            instance = new JdbcTypeHelp();
            instance.initPropertys();
        }
        return instance;
    }

    public void initPropertys() {
        // 加载配置文件
        JavaType.clear();
        JavaType.put("byte", "Byte");
        JavaType.put("short", "Short");
        JavaType.put("int", "Integer");
        JavaType.put("tinyint", "Integer");
        JavaType.put("long", "Long");
        JavaType.put("char", "String");
        JavaType.put("float", "Float");
        JavaType.put("double", "Double");
        JavaType.put("boolean", "Boolean");
        JavaType.put("text", "String");
        JavaType.put("bigint", "Long");
        JavaType.put("varchar", "String");
        JavaType.put("smallint", "Integer");
        JavaType.put("mediumint", "Integer");
        JavaType.put("decimal", "BigDecimal");
        JavaType.put("date", "Date");
        JavaType.put("datetime", "Date");
        JavaType.put("timestamp", "Date");
        JavaType.put("tinytext", "String");
        JavaType.put("mediumtext", "String");
        JavaType.put("longtext", "String");
        // 加载配置文件
        JdbcType.clear();
        JdbcType.put("byte", "TINYINT");
        JdbcType.put("short", "SMALLINT");
        JdbcType.put("int", "INTEGER");
        JdbcType.put("tinyint", "INTEGER");
        JdbcType.put("long", "BIGINT");
        JdbcType.put("char", "CHAR");
        JdbcType.put("float", "FLOAT");
        JdbcType.put("double", "DOUBLE");
        JdbcType.put("boolean", "BOOLEAN");
        JdbcType.put("text", "LONGVARCHAR");
        JdbcType.put("bigint", "BIGINT");
        JdbcType.put("varchar", "VARCHAR");
        JdbcType.put("smallint", "SMALLINT");
        JdbcType.put("mediumint", "INTEGER");
        JdbcType.put("decimal", "DECIMAL");
        JdbcType.put("date", "TIMESTAMP");
        JdbcType.put("datetime", "TIMESTAMP");
        JdbcType.put("timestamp", "TIMESTAMP");
        JdbcType.put("tinytext", "VARCHAR");
        JdbcType.put("mediumtext", "VARCHAR");
        JdbcType.put("longtext", "VARCHAR");
    }

    public String getJavaType(String key) {
        String rtn = JavaType.get(key);
        return rtn;
    }

    public String getJdbcType(String key) {
        String rtn = JdbcType.get(key);
        return rtn;
    }
}
